package com.hejielife.guardedsuspension3;

import java.util.Random;

/**
 * 2019年8月2日 上午11:40:54
 * 
 * @author hejielife
 * @despribe ClientThread
 */
public class ClientThread extends Thread {
	private Random random;
	private RequestQueue requestQueue;

	public ClientThread(RequestQueue requestQueue, String name, long seed) {
		super(name);
		this.requestQueue = requestQueue;
		this.random = new Random(seed);
	}

	public void run() {
		// 线程可能终止，要有异常处理，否则不能停下
		try {
			for (int i = 0; i < 10000; i++) {
				Request request = new Request("No." + i);
				System.out.println(Thread.currentThread().getName() + " requests " + request);
				requestQueue.putRequest(request);
				Thread.sleep(random.nextInt(1000));
			}
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
	}
}
